#include<iostream>
using namespace std;
class CVector {
private:
	int* data;
	int n;
	friend class CMatrix;
public:
	CVector();
	void print();
	CVector(int n1, int* a);
	~CVector();
};
CVector::CVector() {
	n = 5;
	data = new int[n];
	for (int i = 0; i < n; i++) {
		data[i] = i;
	}
}
CVector::CVector(int n1, int* a) {
	n = n1;
	data = new int[n1];
	for (int i = 0; i < n1; i++) {
		data[i] = a[i];
	}
}
void CVector::print() {
	for (int i = 0; i < n; i++) {
		if (i == n - 1) {
			cout << data[i] << endl;
		}
		else {
			cout << data[i] << ' ';
		}
	}
}
CVector::~CVector() {
	delete[] data;
}
class CMatrix {
private:
	int** data;
	int n;
public:
	CMatrix(int n1, int** data1);
	CVector multi(const CVector& v1);
	bool determine(const CVector& v1);
	~CMatrix();
};
CMatrix::CMatrix(int n1, int** data1) {
	n = n1;
	data = new int* [n];
	for (int i = 0; i < n; i++) {
		data[i] = new int[n];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			data[i][j] = data1[i][j];
		}
	}
}
bool CMatrix::determine(const CVector& v1) {
	return n == v1.n;
}
CVector CMatrix::multi(const CVector& v1) {
	int* a = new int[v1.n];
	for (int i = 0; i < n; i++) {
		int m = 0;
		for (int j = 0; j < n; j++) {
			m += data[i][j] * v1.data[j];
		}
		a[i] = m;
	}
	CVector V(n, a);
	delete[]a;
	return V;
}

CMatrix::~CMatrix() {
	for (int i = 0; i < n; i++) {
		delete[]data[i];
	}
	delete[]data;
}
int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int n;
		int m;
		cin >> n;
		int** data = new int* [n];
		for (int i = 0; i < n; i++) {
			data[i] = new int[n];
			for (int j = 0; j < n; j++) {
				cin >> data[i][j];
			}
		}
		CMatrix C(n, data);
		cin >> m;
		int* a = new int[m];
		for (int i = 0; i < m; i++) {
			cin >> a[i];
		}
		CVector v(m, a);
		if (!C.determine(v)) {
			cout << "error" << endl;
		}
		else {
			C.multi(v).print();
		}
		delete[]a;
		for (int i = 0; i < n; i++) {
			delete[]data[i];
		}
		delete[]data;
	}
	return 0;
}